<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <script src="../js/vue.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/echarts/echarts.min.js"></script>
    <!-- 引入ElementUI样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <!-- 引入ElementUI组件库 -->
    <script src="../plugins/elementui/index.js"></script>
    <style>
        .block {
            display: inline
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析<small>套餐占比</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>套餐占比</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div id="app2" style="height:50px;" align="center">
                <div class="block" align="right">
                    <span class="demonstration" align="right">时间</span>
                    <el-date-picker
                            v-model="timeForme"
                            type="daterange"
                            size="mini"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            format="yyyy 年 MM 月 dd 日"
                            value-format="yyyy-MM-dd"
                            :picker-options="pickerOptions">
                    </el-date-picker>
                </div>
                <el-button type="primary" @click="getSetmealReportByTimeForme(timeForme)" size="small">查询</el-button>
            </div>
            <div id="chart1" style="height:600px;"></div>
        </div>
    </div>
</div>

</body>
<!-- 引入组件库 -->

<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('chart1'));

    new Vue({
        el: '#app2',
        data: {
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            timeForme: '',
        },
        created() {
            this.getSetmealReportByTimeForme(this.timeForme);
        },
        methods: {

            getSetmealReportByTimeForme(timeForme){
                axios.get("/report/getSetmealReportByTimeForme.do?timeForme="+this.timeForme).then((res) => {
                    myChart1.setOption({
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b}: {c} ({d}%)'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 10,
                            data: res.data.data.setmealNames
                        },

                        series: [
                            {
                                name: '收入来源',
                                type: 'pie',
                                radius: ['50%', '70%'],
                                avoidLabelOverlap: true,
                                label: {
                                    show: false,
                                    position: 'right'
                                },
                                emphasis: {
                                    label: {
                                        show: true,
                                        fontSize: '15',
                                        fontWeight: 'bold'
                                    }
                                },
                                labelLine: {
                                    show: false
                                },
                                data: res.data.data.setmealCount,
                            }
                        ]
                    });
                    return this.timeForme;
                });
            }

        }

    });

</script>
</html>
